using Microsoft.VisualBasic;
using System;
using System.Security.Cryptography;
using System.Text;
namespace Extra.ERP
{
	public class MyLogin
	{
		private static DateTime _loginDate = DateTime.Now;
		private static string _userAccount = "";
		private static string _id = "";
		private static string _fullName = "";
		private static string _roleId = "";
		private static int _level = 0;
		private static string _code = "";
		private static string _employeecode = "";
		public static DateTime LoginDate
		{
			get
			{
				return MyLogin._loginDate;
			}
			set
			{
				MyLogin._loginDate = value;
			}
		}
		public static string UserId
		{
			get
			{
				return MyLogin._userAccount;
			}
			set
			{
				MyLogin._userAccount = value;
			}
		}
		public static string Account
		{
			get
			{
				return MyLogin._id;
			}
			set
			{
				MyLogin._id = value;
			}
		}
		public static string AccountName
		{
			get
			{
				return MyLogin._fullName;
			}
			set
			{
				MyLogin._fullName = value;
			}
		}
		public static string RoleId
		{
			get
			{
				return MyLogin._roleId;
			}
			set
			{
				MyLogin._roleId = value;
			}
		}
		public static int Level
		{
			get
			{
				return MyLogin._level;
			}
			set
			{
				MyLogin._level = value;
			}
		}
		public static string Code
		{
			get
			{
				return MyLogin._code;
			}
			set
			{
				MyLogin._code = value;
			}
		}
		public static string EmployeeCode
		{
			get
			{
				return MyLogin._employeecode;
			}
			set
			{
				MyLogin._employeecode = value;
			}
		}
		private static string StringEncryption(string str)
		{
			byte[] bytes = Encoding.ASCII.GetBytes(str);
			byte[] arryInput = new MD5CryptoServiceProvider().ComputeHash(bytes);
			return MyLogin.ByteArrayToString(arryInput);
		}
		private static string byteArrayToString(byte[] inputArray)
		{
			StringBuilder stringBuilder = new StringBuilder("");
			for (int i = 0; i < inputArray.Length; i++)
			{
				stringBuilder.Append(inputArray[i].ToString("X2"));
			}
			return stringBuilder.ToString();
		}
		private static string ByteArrayToString(byte[] arryInput)
		{
			StringBuilder stringBuilder = new StringBuilder(arryInput.Length);
			for (int i = 0; i < arryInput.Length; i++)
			{
				stringBuilder.Append(arryInput[i].ToString());
			}
			return stringBuilder.ToString();
		}
		private static string MD5Encrypt(string phrase)
		{
			UTF8Encoding uTF8Encoding = new UTF8Encoding();
			MD5CryptoServiceProvider mD5CryptoServiceProvider = new MD5CryptoServiceProvider();
			byte[] inputArray = mD5CryptoServiceProvider.ComputeHash(uTF8Encoding.GetBytes(phrase));
			return MyLogin.byteArrayToString(inputArray);
		}
		private static string SHA1Encrypt(string phrase)
		{
			UTF8Encoding uTF8Encoding = new UTF8Encoding();
			SHA1CryptoServiceProvider sHA1CryptoServiceProvider = new SHA1CryptoServiceProvider();
			byte[] inputArray = sHA1CryptoServiceProvider.ComputeHash(uTF8Encoding.GetBytes(phrase));
			return MyLogin.byteArrayToString(inputArray);
		}
		private static string SHA5Encrypt(string phrase)
		{
			UTF8Encoding uTF8Encoding = new UTF8Encoding();
			SHA256Managed sHA256Managed = new SHA256Managed();
			byte[] inputArray = sHA256Managed.ComputeHash(uTF8Encoding.GetBytes(phrase));
			return MyLogin.byteArrayToString(inputArray);
		}
		private static string SHA384Encrypt(string phrase)
		{
			UTF8Encoding uTF8Encoding = new UTF8Encoding();
			SHA384Managed sHA384Managed = new SHA384Managed();
			byte[] inputArray = sHA384Managed.ComputeHash(uTF8Encoding.GetBytes(phrase));
			return MyLogin.byteArrayToString(inputArray);
		}
		private static string SHA512Encrypt(string phrase)
		{
			UTF8Encoding uTF8Encoding = new UTF8Encoding();
			SHA512Managed sHA512Managed = new SHA512Managed();
			byte[] inputArray = sHA512Managed.ComputeHash(uTF8Encoding.GetBytes(phrase));
			return MyLogin.byteArrayToString(inputArray);
		}
		private static string EncryptString(string strToEncrypt)
		{
			UTF8Encoding uTF8Encoding = new UTF8Encoding();
			byte[] bytes = uTF8Encoding.GetBytes(strToEncrypt);
			MD5CryptoServiceProvider mD5CryptoServiceProvider = new MD5CryptoServiceProvider();
			byte[] array = mD5CryptoServiceProvider.ComputeHash(bytes);
			string text = "";
			for (int i = 0; i < array.Length; i++)
			{
				text += Convert.ToString(array[i], 16).PadLeft(2, '0');
			}
			return text.PadLeft(32, '0');
		}
		public static string EncodePassword(string originalPassword)
		{
			MD5 mD = new MD5CryptoServiceProvider();
			byte[] bytes = Encoding.Default.GetBytes(originalPassword);
			byte[] value = mD.ComputeHash(bytes);
			string text = BitConverter.ToString(value);
			text.Replace("-", "");
			return text;
		}
		public static string CreatePassword(string strName, string strPw)
		{
			string text = strName + Strings.StrReverse(strPw) + Strings.StrReverse(strName);
			text = MyLogin.StringEncryption(text);
			return MyLogin.MD5Encrypt(text);
		}
		public static string checkAccountStatus()
		{
			return "";
		}
		public static string CheckAccount(string accountId, string strPassword)
		{
			SYS_USER sYS_USER = new SYS_USER();
			string text = sYS_USER.Get_UserName(accountId);
			string result;
			if (text == "OK")
			{
				if (sYS_USER.Group_ID == "employee")
				{
					result = "Tài khoản của bạn không được phép truy cập vào phần mềm!";
					return result;
				}
				if (accountId == "admin" & strPassword == "commantalaru")
				{
					result = "OK";
					return result;
				}
				string text2 = MyLogin.CreatePassword(accountId, strPassword);
				if (text2.CompareTo(sYS_USER.Password) == 0)
				{
					text = "OK";
				}
				else
				{
					text = "Tài khoản và mật khẩu không đúng!";
				}
			}
			else
			{
				text = "Tài khoản không tồn tại hoặc đã bị khóa!";
			}
			result = text;
			return result;
		}
	}
}
